#!/bin/bash
# if database isn't initialized:
if [ ! -f "/root/notedata/leanote.0" ]; then
  #mongod --dbpath /root/notedata --fork --logpath=/var/log/mongodb.log --auth
  mongod --dbpath /root/notedata --fork --logpath=/var/log/mongodb.log
  mongorestore -h localhost -d leanote --directoryperdb /root/leanote/mongodb_backup/leanote_install_data/
  #mongo 127.0.0.1:27017/leanote /root/addUser.js
else
  mongod --dbpath /root/notedata --fork --logpath=/var/log/mongodb.log
fi

#cd /root/leanote/bin; bash run.sh


rm /root/leanote/bin/src/github.com/revel/revel/modules 
cd /root/leanote/bin/src/github.com/revel/revel
ln -s ../modules/ modules

cd /root/leanote/bin
SCRIPTPATH="/root/leanote/bin"
# set link
path="$SCRIPTPATH/src/github.com/leanote"

if [ ! -d "$path" ]; then
  mkdir -p "$path"
fi

rm -rf $SCRIPTPATH/src/github.com/leanote/leanote
ln -s ../../../../ $SCRIPTPATH/src/github.com/leanote/leanote

# set GOPATH
export GOPATH=$SCRIPTPATH
script="$SCRIPTPATH/leanote-linux-amd64"
#chmod 777 $script

$script -importPath github.com/leanote/leanote

